exports.routes = function (app) {
  app.all("*", function (req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    //req.headers["accept-encoding"] && res.setHeader("Content-Encoding", "gzip");
    next();
  });
  require("./modules/fetch").done(app);
  require("./modules/webp").done(app);
  app.all("*", function (req, res, next) {
    var rurl = decodeURIComponent(req.url);
    var pattern = new RegExp(
      "[`~!@#$^&*()=|{}':;',\\[\\].<>/?~！@#￥……&*（）——|{}【】‘；：”“'。，、？%+_]",
      "gim"
    );
    rurl = rurl.replace(pattern, function (a) {
      return "\\" + a.replace(/^\//, "");
    });
    try {
      res.render(rurl, function (err, html) {
        if (err) {
          console.log("->1", err);
          res.render("404", {});
        }
      });
    } catch (e) {
      console.log("->2", e);
      res.render("404", {});
    }
  });
};
